//
//  LoadingConfigView.m
//  aoyunbao
//
//  Created by Hanten on 2017/5/19.
//  Copyright © 2017年 baoduobang. All rights reserved.
//

#import "LoadingConfigView.h"
#import <MBProgressHUD.h>


@implementation LoadingConfigView

- (void)showLoadingView:(UIView *)view offsetY:(CGFloat)offsetY {

    [self showLoadingText:@"" View:view];
}

- (void)showLoadingText:(NSString *)text View:(UIView *)view {
    
    if (!view) {
        view = [UIApplication sharedApplication].keyWindow;
    }
    
    dispatch_async(dispatch_get_main_queue(), ^{
        MBProgressHUD *hub = [MBProgressHUD showHUDAddedTo:view animated:YES];
        [hub hideAnimated:YES afterDelay:20];
        hub.label.text = text;
    });
}

- (void)showLoadingText:(NSString *)text View:(UIView *)view hideTime:(NSTimeInterval)time{
    if (!view) {
        view = [UIApplication sharedApplication].keyWindow;
    }
    
    dispatch_async(dispatch_get_main_queue(), ^{
        MBProgressHUD *hub = [MBProgressHUD showHUDAddedTo:view animated:YES];
        [hub hideAnimated:YES afterDelay:time];
        hub.label.text = text;
    });
}


- (void)hideLoadingView:(UIView *)view {
    
    if (!view) {
        view = [UIApplication sharedApplication].keyWindow;
    }
    
    dispatch_async(dispatch_get_main_queue(), ^{
        [MBProgressHUD hideHUDForView:view animated:YES]; 
    });
}

- (void)showAnimationView:(UIView *)view{
    LoadingView *loadingView = [[LoadingView alloc] initWithFrame:CGRectMake(0, 0, view.width, view.height)];
    loadingView.tag = 99999;
    [view addSubview:loadingView];
}

- (void)hideAnimationLoadingView:(UIView *)view{
    UIView *animationLoadingView = [view viewWithTag:99999];
    
    [animationLoadingView removeFromSuperview];
}

@end
